// pages/zixun/replyAll/replyAll.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    pageNum: 1,
    jjList: [],
    total: 0,
    isLoading: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getData();
  },

  /**
   * 获取数据
   */
  getData() {
    let that = this;
    if (that.data.isLoading) {
      return;
    }
    that.setData({
      isLoading: true
    });
    wx.showLoading({
      title: '正在加载中...',
      icon: 'loading'
    });
    wx.request({
      url: 'http://localhost:8080/userMark/findAll',
      data: {
        pageNum: that.data.pageNum,
        pageSize: 5
      },
      success(resp) {
        let result = resp.data;
        if (result.code === 1) {
          if (that.data.pageNum === 1) {
            that.setData({
              jjList: result.data.list,
              total: result.data.total
            });
          } else {
            that.setData({
              jjList: that.data.jjList.concat(result.data.list),
              total: result.data.total
            });
          }
        } else {
          wx.showToast({
            title: '数据获取失败',
            icon: 'none'
          });
        }
      },
      fail() {
        wx.showToast({
          title: '网络请求失败',
          icon: 'none'
        });
      },
      complete() {
        wx.hideLoading();
        wx.stopPullDownRefresh();
        that.setData({
          isLoading: false
        });
      }
    });
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.setData({
      pageNum: 1,
      jjList: []
    });
    this.getData();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (this.data.isLoading) {
      return;
    }
    if (this.data.pageNum * 5 >= this.data.total) {
      wx.showToast({
        title: '没有更多数据了....',
      });
      return;
    }
    this.setData({
      pageNum: this.data.pageNum + 1
    });
    this.getData();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
});